import com.acxy.ants.common.kit.FileKit;
import com.acxy.ants.common.kit.PathKit;
import com.acxy.ants.core.kit.ScanKit;
import com.acxy.ants.resful.annotation.Controller;
import com.acxy.ants.resful.annotation.POST;
import com.acxy.cms.controller.ArticleAjax;
import com.acxy.cms.entity.Article;

import java.io.File;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 * @author MrShun
 * @version 1.0
 * @Date 2017-10-18
 */
public class MakeDoc {

    private static String startStr = "/**";
    private static String endStr = "*/";

    private static List<String> getFilePath(){
        List<Class<?>> clss = ScanKit.getAnnotatedClass("com.acxy.cms.controller", Controller.class);
        String str = PathKit.getClassPath().replace("target/test-classes/", "") + "src/main/java/";
        List<String> list = new ArrayList<>();
        for(Class cls:  clss){
            String fileName = cls.getName().replace(".", "/")+".java";
            list.add(str + fileName);
        }
        return list;
    }

    public static void main(String[] args) {
//        List<Class<?>> clss = ScanKit.getAnnotatedClass("com.acxy.cms.controller", Controller.class);
//        for(Class cls: clss){
//            Controller c = (Controller) cls.getAnnotation(Controller.class);
//            System.out.println(c.desc());
//            Method[] methods = cls.getMethods();
//            for(Method method: methods){
//                POST post = method.getClass().getAnnotation(POST.class);
//                if(post != null)System.out.println(post.desc());
//                else System.out.println("");
//            }
//        }


        List<String> list = getFilePath();
       // List<String> ls = new ArrayList<>();
        for (String str: list) {
            System.out.println("\n\n =========== 程序开始分析 "+str+" 文件 =========\n");
            String content = FileKit.read(str);
            while (content.indexOf(startStr) != -1){
                int start = content.indexOf(startStr);
                int end = content.indexOf(endStr, start);
                String line = content.substring(start, end+endStr.length());
                content = content.replace(line, "");
                line = line.trim();
                String[] split = line.split("\\* ");
                System.out.println("=== 开始分解 ===");
                //获取功能信息
                System.out.println("功能描述："+ split[2]);
                for(String s: split) {
                    if(s.indexOf("@param") != -1){
                        String[] params = s.split(" ");
                        System.out.println("参数:"+params[1] +" 类型："+params[2]+" 是否必填："+params[3]+" 字段描述："+params[4]+" 错误提示："+params[5]);
                    }else if(s.indexOf("@return") != -1){

                    }
                }
             //   ls.add(line.trim());
            }
        }
    }
}
